﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DevComponents.DotNetBar.Controls;
using DevComponents.DotNetBar.Metro;

namespace MetroControl
{
    public class BaseControlClass<T> where T : BaseUserControl, new()
    {
        protected MetroAppForm _metroAppForm;
        private T t;
        public BaseControlClass() : this(null) { }
        public BaseControlClass(MetroAppForm metroAppForm)
        {
            _metroAppForm = metroAppForm;
        }

        public virtual void OpenControl(eSlideSide eSlideSide = eSlideSide.Left)
        {
            t = new T();
            _metroAppForm.ShowModalPanel(t, eSlideSide);
            t.BindCloseControl(new EventHandler(CloseControlExecuted));
        }

        public virtual void CloseControl(eSlideSide eSlideSide = eSlideSide.Left)
        {
            _metroAppForm.CloseModalPanel(t, eSlideSide);
            t.Dispose();
            t = null;
        }

        private void CloseControlExecuted(object sender, EventArgs e)
        {
            CloseControl();
        }
    }
}
